home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
peak
/
util
/
addons.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
6KB
|
202 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from peak.util.decorators import decorate_class, enclosing_frame, classy
from weakref import ref
import sys
__all__ = [
'AddOn',
'ClassAddOn',
'Registry',
'addons_for']
_addons = { }
def addons_for(ob):
try:
d = ob.__dict__
sd = d.setdefault
return d
except (AttributeError, TypeError):
r = ref(ob)
try:
return _addons[r]
except KeyError:
return _addons.setdefault(ref(ob, _addons.__delitem__), { })
except:
None<EXCEPTION MATCH>KeyError
None<EXCEPTION MATCH>KeyError
def additional_tests():
import doctest as doctest
return doctest.DocFileSuite('README.txt', package = '__main__', optionflags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
class AddOn(classy):
__slots__ = ()
def __class_call__(cls, ob, *data):
a = addons_for(ob)
addon_key = cls.addon_key(*data)
try:
return a[addon_key]
except KeyError:
ob = a.setdefault(addon_key, super(AddOn, cls).__class_call__(ob, *data))
return ob
__class_call__ = classmethod(__class_call__)
def addon_key(cls, *args):
if args:
return (cls,) + args
return cls
addon_key = classmethod(addon_key)
def exists_for(cls, ob, *key):
return cls.addon_key(*key) in addons_for(ob)
exists_for = classmethod(exists_for)
def delete_from(cls, ob, *key):
a = addons_for(ob)
try:
del a[cls.addon_key(*key)]
except KeyError:
pass
delete_from = classmethod(delete_from)
def __init__(self, subject):
pass
class ClassAddOn(AddOn):
__slots__ = ()
def __class_call__(cls, ob, *data):
addon_key = cls.addon_key(*data)
d = ob.__dict__
if addon_key in d:
return d[addon_key]
d2 = addons_for(ob)
try:
return d2[addon_key]
except KeyError:
ob = d2.setdefault(addon_key, super(ClassAddOn, cls).__class_call__(ob, *data))
return ob
__class_call__ = classmethod(__class_call__)
def for_enclosing_class(cls, *args, **kw):
if 'frame' in kw:
frame = kw.pop('frame')
elif 'level' in kw:
level = kw.pop('level')
else:
level = 2
frame = sys._getframe(level)
if kw:
raise TypeError('Unexpected keyword arguments', kw)
return cls.for_frame(frame, *args)
for_enclosing_class = classmethod(for_enclosing_class)
def for_frame(cls, frame, *args):
a = enclosing_frame(frame).f_locals
addon_key = cls.addon_key(*args)
try:
return a[addon_key]
except KeyError:
ob = a.setdefault(addon_key, type.__call__(cls, None, *args))
(decorate_class,)((lambda c: ob._ClassAddOn__decorate(c)), frame = frame)
return ob
for_frame = classmethod(for_frame)
def exists_for(cls, ob, *key):
addon_key = cls.addon_key(*key)
if not addon_key in ob.__dict__:
pass
return addon_key in addons_for(ob)
exists_for = classmethod(exists_for)
def delete_from(cls, ob, *key):
raise TypeError('ClassAddOns cannot be deleted')
delete_from = classmethod(delete_from)
def __decorate(self, cls):
self.created_for(cls)
return cls
def created_for(self, cls):
pass
def __init__(self, subject):
if subject is not None:
self.created_for(subject)
class Registry(ClassAddOn, dict):
__slots__ = ()
def __new__(cls, subject):
if cls is Registry:
raise TypeError('You must subclass Registry to use it')
return super(Registry, cls).__new__(cls)
def __init__(self, subject):
dict.__init__(self)
super(Registry, self).__init__(subject)
def created_for(self, cls):
try:
mro = cls.__mro__[::-1]
except AttributeError:
mro = type(cls.__name__, (cls, object), { }).__mro__[1:][::-1]
data = { }
self.defined_in_class = dict(self)
mytype = type(self)
for base in mro[:-1]:
data.update(mytype(base))
data.update(self)
self.update(data)
def set(self, key, value):
if key in self and self[key] != value:
raise ValueError("%s[%r] already contains %r; can't set to %r" % (self.__class__.__name__, key, self[key], value))
self[key] = value